package behavioral.strategy;

import java.util.HashMap;
import java.util.Map;

// 工厂模式 其实就相当于 你信new 了一个 不重复new
public class PromotionStrategyFactory {
    private static Map<String,PromotionStrategy> PROMOTION_STRING_MAP = new HashMap<>();

    private static final PromotionStrategy NON_PROMOTION = new EmptyPromotionStrategy();

    static {
        //在静态块中把map填充上。
        PROMOTION_STRING_MAP.put(PromotionKey.LiJian,new LiJianPromotionStrategy());

        PROMOTION_STRING_MAP.put(PromotionKey.FanXian,new FanXianPromotionStrategy());

        PROMOTION_STRING_MAP.put(PromotionKey.ManJian,new ManJianPromotionStrategy());
    }

    //这个工厂不希望在外部能够new 出来。
    private PromotionStrategyFactory(){

    }

    public static PromotionStrategy getPromotionStrategy(String promotionKey){
        PromotionStrategy promotionStrategy = PROMOTION_STRING_MAP.get(promotionKey);
        return promotionStrategy == null ? NON_PROMOTION : promotionStrategy;
    }

    private interface PromotionKey{
        String LiJian = "LiJian";
        String FanXian = "FanXian";
        String ManJian = "ManJian";
    }
}
